package com.xyf.sys.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xyf.sys.domain.RegimentAssist;
import com.xyf.sys.domain.RegimentAssistItem;
import com.xyf.sys.service.IRegimentAssistService;
import com.xyf.sys.util.R;
import com.xyf.sys.vo.AssistListRequestVo;
import com.xyf.sys.vo.CartPreOrder;
import com.xyf.sys.vo.PreOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author R-H
 * @Date 2024/6/141436
 * @Description
 */
@RestController
@RequestMapping("/assist")
@Slf4j
@Api(tags = "团长帮忙业务接口")
public class RegimentAssistController {

    @Autowired
    private IRegimentAssistService regimentAssistService;

    @ApiOperation(value = "用户发布", notes = "用户发布")
    @PostMapping("/publish")
    public Object publish(@RequestBody RegimentAssist assist, HttpServletRequest request) {
        String appid = request.getHeader("APPID");
        regimentAssistService.create(assist);
        return R.ok();
    }

    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/list")
    public Object list(@RequestBody AssistListRequestVo requestVo, HttpServletRequest request) {
        PageHelper.startPage(requestVo.getPageNum(), requestVo.getPageSize());
        List<RegimentAssist> orderList = regimentAssistService.getList(requestVo);
        return R.ok(new PageInfo(orderList));
    }

    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/explore")
    public Object explore(@RequestBody AssistListRequestVo requestVo, HttpServletRequest request) {
        PageHelper.startPage(requestVo.getPageNum(), requestVo.getPageSize());
        List<RegimentAssist> orderList = regimentAssistService.exploreList(requestVo);
        return R.ok(new PageInfo(orderList));
    }

    @ApiOperation(value = "团长助力", notes = "团长助力")
    @PostMapping("/increase")
    public Object assist(@RequestBody RegimentAssistItem assist) {
        regimentAssistService.addAssistItem(assist);
        return R.ok();
    }

    @ApiOperation(value = "查询详情", notes = "查询详情")
    @PostMapping("/info")
    public Object info(@RequestBody RegimentAssist assist, HttpServletRequest request) {
        return R.ok(regimentAssistService.getInfo(assist.getId()));
    }

    @ApiOperation(value = "团长获取", notes = "团长获取")
    @PostMapping("/catch")
    public Object catchAssist(@RequestBody RegimentAssist assist, HttpServletRequest request) {
        regimentAssistService.catchAssist(assist);
        return R.ok();
    }

    @ApiOperation(value = "团长完成", notes = "团长完成")
    @PostMapping("/fulfill")
    public Object fulfill(@RequestBody RegimentAssist assist, HttpServletRequest request) {
        regimentAssistService.fulfill(assist);
        return R.ok();
    }


    @ApiOperation(value = "作废", notes = "作废")
    @PostMapping("/remove")
    public Object delete(@RequestBody RegimentAssist assist, HttpServletRequest request) {
        regimentAssistService.remove(assist.getId(), assist.getUserId());
        return R.ok();
    }
}
